/* ----------------------------------------------------------------------
 *	Shadow Quest
 *	Copyright (C) 2009 Prageeth Silva <prageeth@thenewcoders.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *  ----------------------------------------------------------------------
 */
package menu.tabobject;

import java.util.ArrayList;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import sq.RPG;
import sq.FontLoader;

/** Object to be placed in a MenuTab
 * 
 */
public class MenuTabMultiline extends MenuTabObject {

    private ArrayList<String> text;

    public MenuTabMultiline(ArrayList<String> text, float x, float y, Alignment alignemnt, Color color) {

        super(x, y, alignemnt, color);
        this.setText(text);

    }

    public MenuTabMultiline(ArrayList<String> text, float x, float y, Alignment alignemnt) {

        this(text, x, y, alignemnt, Color.black);

    }

    public MenuTabMultiline(ArrayList<String> text, float x, float y) {

        this(text, x, y, Alignment.LEFT);

    }

    public ArrayList<String> getText() {
        return this.text;
    }

    public final void setText(ArrayList<String> text) {
        this.text = text;
    }

    /** Update the game state for a frame.
     * @param input The input object
     * @param delta Time passed since last frame (milliseconds).
     */
    @Override
    public void update(Input input, int delta)
            throws SlickException {
        // do nothing
    }

    /** Render the entire screen, so it reflects the current game state.
     * @param g The Slick graphics object, used for drawing.
     */
    @Override
    public void render(Graphics g)
            throws SlickException {

        g.setColor(this.getColor());
        g.setFont(FontLoader.getFontSize12());
        float height = g.getFont().getLineHeight();
        float y = this.getY();

        for(String s : this.getText())
        {
            if (this.getAlignment() == Alignment.RIGHT)
            {
                int width = g.getFont().getWidth(s);
                g.drawString(s, this.getX() - width, y);
            }
            else if (this.getAlignment() == Alignment.CENTER)
            {
                int width = g.getFont().getWidth(s);
                g.drawString(s, (RPG.getScreenWidth() - width) / 2, y);
            }
            else
            {
                g.drawString(s, this.getX(), y);
            }
            y += 1.5f * height;
        }

    }

    @Override
    public void resetValue() {
        // do nothing
    }

    @Override
    public void saveValue() {
        // do nothing
    }
}
